package org.abc.fund.entity.funds;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 基金基本信息实体
 */
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Entity
@Table(name = "fund_basic_info", indexes = {
        @Index(name = "idx_main_code", columnList = "main_code", unique = true),
        @Index(name = "idx_start_date", columnList = "start_date")
})
@Data
public class FundBasicInfo {

    @Id
    @Column(name = "fund_code", length = 20)
    private String code;
    @Column(name = "main_code", length = 12, unique = true)
    private String mainCode;

    @Column(name = "statistics_main_code", length = 32)
    private String statisticsMainCode;

    @Column(name = "name", length = 100)
    private String name;

    @Column(name = "type", length = 50)
    private String type;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "advisor")
    private FundManager manager;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "trustee")
    private FundCompany company;

    @Column(name = "status", length = 20)
    private String status;

    @Column(name = "latest_nav", precision = 15, scale = 6)
    private BigDecimal latestNav;

    @Column(name = "latest_nav_date")
    private LocalDate latestNavDate;

    @Column(name = "latest_est_nav", precision = 15, scale = 6)
    private BigDecimal latestEstNav;

    @Column(name = "latest_est_rate", precision = 10, scale = 6)
    private BigDecimal latestEstRate;

    @Column(name = "operate_mode_id")
    private Integer operateModeId;

    @Column(name = "operate_mode", length = 32)
    private String operateMode;

    @Column(name = "underlying_asset_type_id")
    private Integer underlyingAssetTypeId;

    @Column(name = "underlying_asset_type", length = 32)
    private String underlyingAssetType;

    @Column(name = "start_date")
    private LocalDate startDate;

    @Column(name= "fund_type")
    private String  fundType;
    @Column(name = "pub_date")
    private LocalDate pubDate;

    @Column(name = "end_date")
    private LocalDate endDate;

    @Column(name = "invest_style_id")
    private Integer investStyleId;

    @Column(name = "invest_style", length = 32)
    private String investStyle;

    @Column(name = "collected_at")
    private LocalDateTime collectedAt;

    @PrePersist
    protected void onCreate() {
        if (collectedAt == null) {
            collectedAt = LocalDateTime.now();
        }
    }
}
